home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7947 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  48 lines

  1. Newsgroups: comp.lang.c
  2. Path: netcom.com!raffelm
  3. From: raffelm@netcom.com (Matt Raffel)
  4. Subject: Example using vfprintf
  5. Message-ID: <raffelmDnK19L.IH6@netcom.com>
  6. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  7. X-Newsreader: TIN [version 1.2 PL1]
  8. Date: Thu, 29 Feb 1996 20:36:57 GMT
  9. Sender: raffelm@netcom8.netcom.com
  10.  
  11. I am hoping someone can show me a simple example of 
  12. using vfprintf.  I cannot find one in the sources
  13. I have.
  14.  
  15. I am attempting to "encapsulate" vfprintf so that
  16. I do not have to worry about keeping track of
  17. a file pointer.  See code below...
  18.  
  19. void lprintf(char *pszFormat, ...)
  20. {
  21.    FILE *pstFile = NULL;
  22.  
  23.    pstFile = fopen("llog.txt", "wt+");
  24.  
  25.    if (pstFile)
  26.    {
  27.       vfprintf(pstFile, pszFormat, ...);
  28.       fclose(pstFile);
  29.    }
  30.  
  31. }
  32.  
  33. I know the above may be a bit slow with always
  34. opening and closing...but at least I will have
  35. the contents of the file when my program poofs in
  36. the middle in execution. :)
  37.  
  38. Thanks!
  39.  
  40.  
  41. Matt
  42. PS:  this code is for SUN Unix (if that makes
  43. any difference).
  44. -- 
  45. raffelm@netcom.com
  46. Web Page  ftp://ftp.netcom.com/ra/raffelm/isdhome.html
  47.           ftp://ftp.netcom.com/ra/raffelm/homeofmatt.html 
  48.